
set LIBP $env(AIOSS_HOME)/lib
load $env(AIOSS_HOME)/lib/libTxtTcl.so

global _bms_proto_convert
global dbConnection
set _bms_proto_convert ""

proc _TI_SERIAL {proto} {
	global dbConnection
	set handle $dbConnection
	set s_formid [query $handle "select IMDUID, MSGTYP, PTXNCD, FORMID, PROCID, DESCB from bms_formid where IMDUID='$proto'" ]
	set s_flddef [query $handle "select a.FORMID, a.FLDSQN, a.FLDNAM, a.FLDATT, a.LENFLG, a.VARLEN, a.OFFFLG, a.OFFSET, a.ALIFLG, a.FILFLG, a.FILCHR, a.COMFID, a.RECFLG, a.FIXFLG, a.FIXVAL from bms_flddef a, bms_formid b where b.IMDUID='$proto' and b.FORMID=a.FORMID order by a.FORMID, cast(a.FLDSQN as unsigned)" ]

	set s_servicedef [query $handle "select a.SERVICE_NAME, a.PARAM_LIST, a.RESULT_LIST from i_def_service a, bms_formid b where IMDUID='$proto' and a.FORMID=b.FORMID and MSGTYP=1" ]
	set serial "\{BMS_FORMID \{$s_formid\}\} \{BMS_FLDDEF \{$s_flddef\}\} \{SERVICE_DEF \{$s_servicedef\}\}"
	puts "serial=$serial"
	_GET_BMS_PROTO_CONVERT
	return $serial;
}


proc query {handle sql } {
	set rows [::mysql::sel $handle $sql -list]
	puts "handle:$handle"
	return $rows
}


proc _GET_BMS_PROTO_CONVERT {} {
        global _bms_proto_convert
	global dbConnection
	set handle $dbConnection
	if {$_bms_proto_convert != ""}  {
		return 
	}
        set s_proto_convert [query $handle "select IMDUID, trim(PTXNCD), FORMID, trim(PARAM_LIST), trim(RESULT_LIST) from bms_proto_convert "]
        set serial "\{BMS_PROTO_CONVERT \{$s_proto_convert\}\}"
        set _bms_proto_convert $serial
	puts "dbConnection:$dbConnection ,_bms_proto_convert=$_bms_proto_convert"
        return $serial;
}

_TI_SERIAL DC 
